/**
 * zhanjun
 */

$(function() {

	
	var urlId="";
	var urlkey="id";
	//解析获取的url id参数
	var reg = new RegExp("(^|&)"+urlkey+"=([^&]*)(&|$)","i");
	var r = window.location.search.substr(1).match(reg);	 	   
	if (r!=null) 
	{	
		urlId=unescape(r[2]); 		
	}
	
	/*
	 * 初始加载数据
	 */
	$.getJSON("../user/ser_load.do?id="+urlId, function(data) {
		if(data){			
			$("#userName").attr("value",data.userName);
			$("#nickName").attr("value",data.nickName);
			
			$("#idUser").attr("value",data.idUser);
			$("#password").attr("value",data.password);
			$("#icq").attr("value",data.icq);
			$("#email").attr("value",data.email);
			$("#phone").attr("value",data.phone);
			$("#city").attr("value",data.city);
			$("#comment").attr("value",data.comment);
			$("#sign").attr("value",data.sign);
			var vgender=data.sex;
			 $('#cityval').html("["+data.city+"]");
			document.getElementById("sex").value=vgender;//性别赋值
		
			$("#citycode")[0].options.length = 0;
			$('#citycode').combotree({
				//初始化分类
			 url:'../region/ser_getRegions.do',
				 onSelect:function(node){			
					   var isleaf = $('#citycode').combotree('tree').tree('isLeaf',node.target);
					   if(!isleaf){
						   alert("请选择具体的子节点！");
						   $('#citycode').combotree('clear');
						   $('#cityval').html("");
						   $("#city").attr("value","");
						   return false;
					   }
					   $("#city").attr("value",node.attributes);
					   $('#cityval').html("["+node.attributes+"]");
				}   
			 
			});
			$("#citycode").combotree('setValue',data.citycode);
		}else{
			alert("数据载入出错!");
			history.go(-1);
		}

	});

	
	/*
	 * 更新事件
	 */

	$("#btn_submit").click(function() {
		var postdata = $('#dataform').serialize();
		if($('#dataform').form('validate')){	
		$.ajax({
			type : "POST",
			url : "../user/ser_update.do",
			data : postdata,
			success : function(msg) {
				alert(msg);
				history.go(-1);
				
			}
		});
		}
	});

});
